package com.ruoyi.portal.service.impl;

import com.ruoyi.common.core.domain.entity.Regexregisteredservice;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.portal.mapper.ServicesMapper;
import com.ruoyi.portal.service.ServicesService;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServicesServiceImpl implements ServicesService {
  @Autowired
  ServicesMapper servicesMapper;
  @Autowired
  SysUserMapper sysUserMapper;

  public List<Regexregisteredservice> getServicesByUserId(long userId) {
    return servicesMapper.getServicesByUserId(userId);
  }

  public int delUserServiceByServiceIdUserId(long userId, long serviceId) {
    return servicesMapper.delUserServiceByServiceIdUserId(userId, serviceId);
  }

  public int addUserServiceByServiceIdUserId(String username, long serviceId) {
    SysUser user = sysUserMapper.selectUserByUserName(username);
    long userId = user.getUserId();
    int num = servicesMapper.isUserIdServiceId(userId, serviceId);
    if (num > 0) {
      return -1;
    }
    return servicesMapper.addUserServiceByServiceIdUserId(userId, serviceId);
  }

}
